import { FormSchema, BasicColumn } from "/@/components/Table"
import { isRoleExist, listMenuScheme } from "/@/api/sys/role"
import { DescItem } from "/@/components/Description/index"
import { render } from "/@/utils/common/renderUtils"

export enum RoleEnum {
  OWNER = "owner",
  ADMIN = "admin",
  MEMBER = "member",
}

export const columns : BasicColumn[] = [
  {
    title: "角色名称",
    dataIndex: "roleName",
    width: 100,
  },
  {
    title: "角色编码",
    dataIndex: "roleCode",
    width: 100,
  },
  {
    title: "默认角色",
    dataIndex: "defaultFlag",
    customRender: ({ text }) => {
      return render.renderTag(text ? "是" : "否", text ? "green" : "blue")
    },
    width: 60,
  },
  {
    title: "说明",
    dataIndex: "remark",
    align: "left",
    width: 180,
  }
]

export const roleSubjectColumns = [
  {
    title: "主体名称",
    dataIndex: "subjectName",
    width: 100,
  },
  {
    title: "主体类型",
    dataIndex: "subjectTypeName",
    width: 100,
  },
  {
    title: "加入时间",
    dataIndex: "createdAt",
    width: 160,
  },
]
export const searchFormSchema: FormSchema[] = [
  {
    field: "roleName",
    label: "角色名称",
    component: "Input",
    colProps: { span: 6 },
  },
]


export const searchUserFormSchema: FormSchema[] = [
  {
    field: "keyword",
    label: "主体名称",
    component: "Input",
    colProps: { span: 12 },
    componentProps: {
      placeholder: "请输入"
    },
  },
  {
    field: "subjectType",
    label: "主体类型",
    component: "JDictSelectTag",
    colProps: { span: 12 },
    componentProps: {
      placeholder: "全部",
      chooseOptionLabel: "全部",
      dictType: "RoleSubjectType",
    },
  },
]

export const formSchema: FormSchema[] = [
  {
    field: "id",
    label: "",
    component: "Input",
    show: false,
  },
  {
    field: "roleName",
    label: "角色名称",
    required: true,
    component: "Input",
  },
  {
    field: "roleCode",
    label: "角色编码",
    dynamicDisabled: ({ values }) => {
      return !!values.id
    },
    required: true,
    component: "Input",
  },
  {
    field: "defaultFlag",
    label: "默认角色",
    component: "RadioGroup",
    defaultValue: false,
    componentProps: {
      options: [
        { label: "是", value: true },
        { label: "否", value: false },
      ],
    },
  },
  {
    label: "备注",
    field: "remark",
    component: "InputTextArea",
    componentProps: {
      placeholder: "请输入备注",
      rows: 5,
    },
  },
]

export const formRolePermissionSchema: FormSchema[] = [
  {
    label: "场景",
    field: "sceneCode",
    component: "ApiSelect",
  },
]

export const formDetailSchema: DescItem[] = [
  {
    field: "id",
    label: "角色ID",
  },
  {
    field: "roleName",
    label: "角色名称",
  },
  {
    field: "roleCode",
    label: "角色编码",
  },
  {
    field: "createdAt",
    label: "创建时间",
  },
  {
    field: "createdBy",
    label: "创建者",
  },
  {
    label: "备注",
    labelMinWidth: 60,
    field: "remark",
  },
]
